if object_id('ExternalCallSurvey') is null
begin
	CREATE TABLE [dbo].[ExternalCallSurvey](
		[Id] [uniqueidentifier] NOT NULL,
		[DateCreated] [datetime] NOT NULL,
		[AgentId] [uniqueidentifier] NOT NULL,
		[CustomerId] [uniqueidentifier] NOT NULL,
		[PhoneNumber] [nvarchar](100) NOT NULL,
		[CustomerAgree] [bit] NOT NULL,
		[Scrore] [numeric](18, 2) NULL
	) ON [PRIMARY]
	end
GO
drop Procedure [dbo].[spCALLBACK_UpdateScore]
go
create Procedure [dbo].[spCALLBACK_UpdateScore]
	( @PhoneNumber nvarchar(100)
	, @Score numeric(18,2)
	)
as
  begin
	set nocount on
	declare @id uniqueidentifier
	
	select  top 1 @id =id from ExternalCallSurvey 
	where PhoneNumber=@PhoneNumber 	
	order by DateCreated desc
	
	if (@id is not null)
	begin
		update ExternalCallSurvey set Scrore=@Score where id=@id
	end
	
  end
